package jp.co.ricoh.melody.presenters;

import android.view.View;

import jp.co.ricoh.melody.databases.DBManager;
import jp.co.ricoh.melody.models.AlarmModel;
import jp.co.ricoh.melody.views.activities.IMainActivityView;

/**
 * Copyright (C) 2016 RICOH Co.,LTD.
 * All rights reserved.
 */
public class MainActivityPresenter
        implements IMainActivityPresenter, AlarmModel.OnAlarmDataSetChangedListener {

    private static final int MAX_ALARM = 100;
    private IMainActivityView mIMainActivityView;
    private AlarmModel mAlarmModel = AlarmModel.getInstance();

    public MainActivityPresenter() {
        mAlarmModel.addOnAlarmDataSetChangedListener(this);
    }

    @Override
    public void onCreateView(IMainActivityView view) {
        mIMainActivityView = view;
        updateAddButtonGuideVisibility(DBManager.getInstance().isFirstAdd());
    }

    @Override
    public void updateAddButtonGuideVisibility(boolean visible) {
        if (mIMainActivityView != null) {
            mIMainActivityView.setAddButtonGuideVisibility(visible ? View.VISIBLE : View.GONE);
        }
    }

    @Override
    public void onDestroyView() {
        this.mIMainActivityView = null;
    }

    @Override
    public void setFirstAdd() {
        mAlarmModel.setFirstAddAlarm();
    }

    @Override
    public void onAlarmAdded(int alarmId) {

    }

    @Override
    public void onAlarmDeleted(int alarmId) {

    }

    @Override
    public void onAlarmChanged(int alarmId) {

    }

    @Override
    public void transitToAddAlarmScreen() {
        if (mIMainActivityView != null) {
            if (mAlarmModel.getAlarmList().size() < MAX_ALARM) {
                mIMainActivityView.navigateToAddAlarmActivity();
            } else {
                mIMainActivityView.showMessageAlarmSizeHasReachMax();
            }
        }
    }



    @Override
    public boolean isFirstAdd() {
        return mAlarmModel.isFirstAddAlarm();
    }

    @Override
    public void transitToMpteListScreen() {
        mIMainActivityView.transitToNoteListActivity();
    }
}
